{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Importing PulP solver\n",
    "from pulp import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Inputing the demand points\n",
    "demand_points=['Mina Salman','Larnaca Port','Port of Alexandria','Port of Bandar Abbas','Port of Umm Qasr','Port of Haifa','Port of Aqaba','Port of Shuwaikh','Port of Beirut','Port of Salalah','Port of Gaza','Port of Doha','Port of King Abdul Aziz','Port of Jeddah','Port of Latakia','Port of Mersin','Port of Jebel Ali','Port of Hodeidah']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Inputing the Supply points\n",
    "supply_points=['Port of Salalah', 'Port of Gaza','Port of Jebel Ali']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Inputing the distances\n",
    "distance = dict(zip(supply_points,[dict(zip(demand_points, [174.9461,1532.2683,1677.2683,554.9461,531.8835,1352.2683,1407.9919,460.8835,1414.4714,0,1435.2683,314.9461,257.8835,1093.7369,1549.4368,1585.2683,501.9461,833])),\n",
    "dict(zip(demand_points, [1260.3222,207,242,1598.7564,1084.728,83,445.0412,1065.9377,153,1435.2683,0,1400.3222,1233.7564,828,248,316,1587.3222,1275])),\n",
    "dict(zip(demand_points, [327,1684.3222,1829.3222,173,606,1504.3222,1560.0458,562,1566.5253,501.9461,1587.3222,187,389,1231.102,1629.758,1718.758,0,1180.4128]))]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Constraint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "vehicle_demands=dict(zip(demand_points, [52926740.45,20211709.62,219933980,150919247.3,216546853.3,219082653.4,107530347.6,133005844.6,49856593.12,150185708.1,11357941.91,55444187.63,255172735.5,255172735.5,30226871.78,133474473.2,494016476.8,16109213.06\n",
    "]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Decision Variables\n",
    "X = LpVariable.dicts('X%s%s', (supply_points,demand_points),\n",
    "                     cat = 'Binary',\n",
    "                     lowBound = 0,\n",
    "                     upBound = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Setting up the minimization problem\n",
    "\n",
    "prob=LpProblem ('P Median',LpMinimize)\n",
    "prob+= sum(sum(vehicle_demands[j]*distance[i][j]*X[i][j] for j in demand_points)for i in supply_points)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "P Median:\n",
       "MINIMIZE\n",
       "4183823891.34*XPort_of_GazaLarnaca_Port + 66704745962.772995*XPort_of_GazaMina_Salman + 53224023160*XPort_of_GazaPort_of_Alexandria + 47855434932.32112*XPort_of_GazaPort_of_Aqaba + 241283112504.05774*XPort_of_GazaPort_of_Bandar_Abbas + 7628058747.36*XPort_of_GazaPort_of_Beirut + 77639726799.2544*XPort_of_GazaPort_of_Doha + 18183860232.2*XPort_of_GazaPort_of_Haifa + 20539246651.5*XPort_of_GazaPort_of_Hodeidah + 784163320790.425*XPort_of_GazaPort_of_Jebel_Ali + 211283024994.0*XPort_of_GazaPort_of_Jeddah + 314820995528.6322*XPort_of_GazaPort_of_King_Abdul_Aziz + 7496264201.440001*XPort_of_GazaPort_of_Latakia + 42177933531.200005*XPort_of_GazaPort_of_Mersin + 215556785948.98322*XPort_of_GazaPort_of_Salalah + 141775944079.4814*XPort_of_GazaPort_of_Shuwaikh + 234894435086.40244*XPort_of_GazaPort_of_Umm_Qasr + 34043031212.919567*XPort_of_Jebel_AliLarnaca_Port + 17307044127.15*XPort_of_Jebel_AliMina_Salman + 402330112148.356*XPort_of_Jebel_AliPort_of_Alexandria + 167752267145.92007*XPort_of_Jebel_AliPort_of_Aqaba + 26109029782.9*XPort_of_Jebel_AliPort_of_Bandar_Abbas + 78101614494.28593*XPort_of_Jebel_AliPort_of_Beirut + 10368063086.810001*XPort_of_Jebel_AliPort_of_Doha + 18028713340.053402*XPort_of_Jebel_AliPort_of_Gaza + 329570899144.5255*XPort_of_Jebel_AliPort_of_Haifa + 19015521293.951168*XPort_of_Jebel_AliPort_of_Hodeidah + 314143665019.521*XPort_of_Jebel_AliPort_of_Jeddah + 99262194109.5*XPort_of_Jebel_AliPort_of_King_Abdul_Aziz + 49262486098.429245*XPort_of_Jebel_AliPort_of_Latakia + 229410318608.2856*XPort_of_Jebel_AliPort_of_Mersin + 75385130456.5334*XPort_of_Jebel_AliPort_of_Salalah + 74749284665.2*XPort_of_Jebel_AliPort_of_Shuwaikh + 131227393099.8*XPort_of_Jebel_AliPort_of_Umm_Qasr + 30969761939.531048*XPort_of_SalalahLarnaca_Port + 9259326827.439745*XPort_of_SalalahMina_Salman + 368888292746.834*XPort_of_SalalahPort_of_Alexandria + 151401858424.98444*XPort_of_SalalahPort_of_Aqaba + 83752047704.07054*XPort_of_SalalahPort_of_Bandar_Abbas + 70520725069.67676*XPort_of_SalalahPort_of_Beirut + 17461930661.736744*XPort_of_SalalahPort_of_Doha + 16301693976.664454*XPort_of_SalalahPort_of_Gaza + 296258527272.7072*XPort_of_SalalahPort_of_Haifa + 13418974478.98*XPort_of_SalalahPort_of_Hodeidah + 247969643865.5005*XPort_of_SalalahPort_of_Jebel_Ali + 279091836690.29*XPort_of_SalalahPort_of_Jeddah + 65804838135.314255*XPort_of_SalalahPort_of_King_Abdul_Aziz + 46834627484.81351*XPort_of_SalalahPort_of_Latakia + 211592851223.15955*XPort_of_SalalahPort_of_Mersin + 61300199179.7041*XPort_of_SalalahPort_of_Shuwaikh + 115177698247.19057*XPort_of_SalalahPort_of_Umm_Qasr + 0.0\n",
       "SUBJECT TO\n",
       "_C1: XPort_of_GazaPort_of_Gaza + XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_SalalahPort_of_Salalah = 3\n",
       "\n",
       "_C2: XPort_of_GazaMina_Salman + XPort_of_Jebel_AliMina_Salman\n",
       " + XPort_of_SalalahMina_Salman = 1\n",
       "\n",
       "_C3: XPort_of_GazaLarnaca_Port + XPort_of_Jebel_AliLarnaca_Port\n",
       " + XPort_of_SalalahLarnaca_Port = 1\n",
       "\n",
       "_C4: XPort_of_GazaPort_of_Alexandria + XPort_of_Jebel_AliPort_of_Alexandria\n",
       " + XPort_of_SalalahPort_of_Alexandria = 1\n",
       "\n",
       "_C5: XPort_of_GazaPort_of_Bandar_Abbas\n",
       " + XPort_of_Jebel_AliPort_of_Bandar_Abbas\n",
       " + XPort_of_SalalahPort_of_Bandar_Abbas = 1\n",
       "\n",
       "_C6: XPort_of_GazaPort_of_Umm_Qasr + XPort_of_Jebel_AliPort_of_Umm_Qasr\n",
       " + XPort_of_SalalahPort_of_Umm_Qasr = 1\n",
       "\n",
       "_C7: XPort_of_GazaPort_of_Haifa + XPort_of_Jebel_AliPort_of_Haifa\n",
       " + XPort_of_SalalahPort_of_Haifa = 1\n",
       "\n",
       "_C8: XPort_of_GazaPort_of_Aqaba + XPort_of_Jebel_AliPort_of_Aqaba\n",
       " + XPort_of_SalalahPort_of_Aqaba = 1\n",
       "\n",
       "_C9: XPort_of_GazaPort_of_Shuwaikh + XPort_of_Jebel_AliPort_of_Shuwaikh\n",
       " + XPort_of_SalalahPort_of_Shuwaikh = 1\n",
       "\n",
       "_C10: XPort_of_GazaPort_of_Beirut + XPort_of_Jebel_AliPort_of_Beirut\n",
       " + XPort_of_SalalahPort_of_Beirut = 1\n",
       "\n",
       "_C11: XPort_of_GazaPort_of_Salalah + XPort_of_Jebel_AliPort_of_Salalah\n",
       " + XPort_of_SalalahPort_of_Salalah = 1\n",
       "\n",
       "_C12: XPort_of_GazaPort_of_Gaza + XPort_of_Jebel_AliPort_of_Gaza\n",
       " + XPort_of_SalalahPort_of_Gaza = 1\n",
       "\n",
       "_C13: XPort_of_GazaPort_of_Doha + XPort_of_Jebel_AliPort_of_Doha\n",
       " + XPort_of_SalalahPort_of_Doha = 1\n",
       "\n",
       "_C14: XPort_of_GazaPort_of_King_Abdul_Aziz\n",
       " + XPort_of_Jebel_AliPort_of_King_Abdul_Aziz\n",
       " + XPort_of_SalalahPort_of_King_Abdul_Aziz = 1\n",
       "\n",
       "_C15: XPort_of_GazaPort_of_Jeddah + XPort_of_Jebel_AliPort_of_Jeddah\n",
       " + XPort_of_SalalahPort_of_Jeddah = 1\n",
       "\n",
       "_C16: XPort_of_GazaPort_of_Latakia + XPort_of_Jebel_AliPort_of_Latakia\n",
       " + XPort_of_SalalahPort_of_Latakia = 1\n",
       "\n",
       "_C17: XPort_of_GazaPort_of_Mersin + XPort_of_Jebel_AliPort_of_Mersin\n",
       " + XPort_of_SalalahPort_of_Mersin = 1\n",
       "\n",
       "_C18: XPort_of_GazaPort_of_Jebel_Ali + XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_SalalahPort_of_Jebel_Ali = 1\n",
       "\n",
       "_C19: XPort_of_GazaPort_of_Hodeidah + XPort_of_Jebel_AliPort_of_Hodeidah\n",
       " + XPort_of_SalalahPort_of_Hodeidah = 1\n",
       "\n",
       "_C20: XPort_of_SalalahMina_Salman - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C21: XPort_of_GazaMina_Salman - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C22: XPort_of_Jebel_AliMina_Salman - XPort_of_Jebel_AliPort_of_Jebel_Ali <= 0\n",
       "\n",
       "_C23: XPort_of_SalalahLarnaca_Port - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C24: XPort_of_GazaLarnaca_Port - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C25: XPort_of_Jebel_AliLarnaca_Port - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C26: XPort_of_SalalahPort_of_Alexandria - XPort_of_SalalahPort_of_Salalah\n",
       " <= 0\n",
       "\n",
       "_C27: XPort_of_GazaPort_of_Alexandria - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C28: XPort_of_Jebel_AliPort_of_Alexandria\n",
       " - XPort_of_Jebel_AliPort_of_Jebel_Ali <= 0\n",
       "\n",
       "_C29: XPort_of_SalalahPort_of_Bandar_Abbas - XPort_of_SalalahPort_of_Salalah\n",
       " <= 0\n",
       "\n",
       "_C30: XPort_of_GazaPort_of_Bandar_Abbas - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C31: XPort_of_Jebel_AliPort_of_Bandar_Abbas\n",
       " - XPort_of_Jebel_AliPort_of_Jebel_Ali <= 0\n",
       "\n",
       "_C32: - XPort_of_SalalahPort_of_Salalah + XPort_of_SalalahPort_of_Umm_Qasr\n",
       " <= 0\n",
       "\n",
       "_C33: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Umm_Qasr <= 0\n",
       "\n",
       "_C34: - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_Jebel_AliPort_of_Umm_Qasr <= 0\n",
       "\n",
       "_C35: XPort_of_SalalahPort_of_Haifa - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C36: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Haifa <= 0\n",
       "\n",
       "_C37: XPort_of_Jebel_AliPort_of_Haifa - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C38: XPort_of_SalalahPort_of_Aqaba - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C39: XPort_of_GazaPort_of_Aqaba - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C40: XPort_of_Jebel_AliPort_of_Aqaba - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C41: - XPort_of_SalalahPort_of_Salalah + XPort_of_SalalahPort_of_Shuwaikh\n",
       " <= 0\n",
       "\n",
       "_C42: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Shuwaikh <= 0\n",
       "\n",
       "_C43: - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_Jebel_AliPort_of_Shuwaikh <= 0\n",
       "\n",
       "_C44: XPort_of_SalalahPort_of_Beirut - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C45: XPort_of_GazaPort_of_Beirut - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C46: XPort_of_Jebel_AliPort_of_Beirut - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C47: 0 XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C48: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Salalah <= 0\n",
       "\n",
       "_C49: - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_Jebel_AliPort_of_Salalah <= 0\n",
       "\n",
       "_C50: XPort_of_SalalahPort_of_Gaza - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C51: 0 XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C52: XPort_of_Jebel_AliPort_of_Gaza - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C53: XPort_of_SalalahPort_of_Doha - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C54: XPort_of_GazaPort_of_Doha - XPort_of_GazaPort_of_Gaza <= 0\n",
       "\n",
       "_C55: XPort_of_Jebel_AliPort_of_Doha - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C56: XPort_of_SalalahPort_of_King_Abdul_Aziz\n",
       " - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C57: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_King_Abdul_Aziz <= 0\n",
       "\n",
       "_C58: - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_Jebel_AliPort_of_King_Abdul_Aziz <= 0\n",
       "\n",
       "_C59: XPort_of_SalalahPort_of_Jeddah - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C60: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Jeddah <= 0\n",
       "\n",
       "_C61: - XPort_of_Jebel_AliPort_of_Jebel_Ali + XPort_of_Jebel_AliPort_of_Jeddah\n",
       " <= 0\n",
       "\n",
       "_C62: XPort_of_SalalahPort_of_Latakia - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C63: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Latakia <= 0\n",
       "\n",
       "_C64: - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + XPort_of_Jebel_AliPort_of_Latakia <= 0\n",
       "\n",
       "_C65: XPort_of_SalalahPort_of_Mersin - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C66: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Mersin <= 0\n",
       "\n",
       "_C67: - XPort_of_Jebel_AliPort_of_Jebel_Ali + XPort_of_Jebel_AliPort_of_Mersin\n",
       " <= 0\n",
       "\n",
       "_C68: XPort_of_SalalahPort_of_Jebel_Ali - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C69: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Jebel_Ali <= 0\n",
       "\n",
       "_C70: 0 XPort_of_Jebel_AliPort_of_Jebel_Ali <= 0\n",
       "\n",
       "_C71: XPort_of_SalalahPort_of_Hodeidah - XPort_of_SalalahPort_of_Salalah <= 0\n",
       "\n",
       "_C72: - XPort_of_GazaPort_of_Gaza + XPort_of_GazaPort_of_Hodeidah <= 0\n",
       "\n",
       "_C73: XPort_of_Jebel_AliPort_of_Hodeidah - XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " <= 0\n",
       "\n",
       "_C74: 20211709.62 XPort_of_SalalahLarnaca_Port\n",
       " + 52926740.45 XPort_of_SalalahMina_Salman\n",
       " + 219933980 XPort_of_SalalahPort_of_Alexandria\n",
       " + 107530347.6 XPort_of_SalalahPort_of_Aqaba\n",
       " + 150919247.3 XPort_of_SalalahPort_of_Bandar_Abbas\n",
       " + 49856593.12 XPort_of_SalalahPort_of_Beirut\n",
       " + 55444187.63 XPort_of_SalalahPort_of_Doha\n",
       " + 11357941.91 XPort_of_SalalahPort_of_Gaza\n",
       " + 219082653.4 XPort_of_SalalahPort_of_Haifa\n",
       " + 16109213.06 XPort_of_SalalahPort_of_Hodeidah\n",
       " + 494016476.8 XPort_of_SalalahPort_of_Jebel_Ali\n",
       " + 255172735.5 XPort_of_SalalahPort_of_Jeddah\n",
       " + 255172735.5 XPort_of_SalalahPort_of_King_Abdul_Aziz\n",
       " + 30226871.78 XPort_of_SalalahPort_of_Latakia\n",
       " + 133474473.2 XPort_of_SalalahPort_of_Mersin\n",
       " + 150185708.1 XPort_of_SalalahPort_of_Salalah\n",
       " + 133005844.6 XPort_of_SalalahPort_of_Shuwaikh\n",
       " + 216546853.3 XPort_of_SalalahPort_of_Umm_Qasr <= 920430000\n",
       "\n",
       "_C75: 20211709.62 XPort_of_GazaLarnaca_Port\n",
       " + 52926740.45 XPort_of_GazaMina_Salman\n",
       " + 219933980 XPort_of_GazaPort_of_Alexandria\n",
       " + 107530347.6 XPort_of_GazaPort_of_Aqaba\n",
       " + 150919247.3 XPort_of_GazaPort_of_Bandar_Abbas\n",
       " + 49856593.12 XPort_of_GazaPort_of_Beirut\n",
       " + 55444187.63 XPort_of_GazaPort_of_Doha\n",
       " + 11357941.91 XPort_of_GazaPort_of_Gaza\n",
       " + 219082653.4 XPort_of_GazaPort_of_Haifa\n",
       " + 16109213.06 XPort_of_GazaPort_of_Hodeidah\n",
       " + 494016476.8 XPort_of_GazaPort_of_Jebel_Ali\n",
       " + 255172735.5 XPort_of_GazaPort_of_Jeddah\n",
       " + 255172735.5 XPort_of_GazaPort_of_King_Abdul_Aziz\n",
       " + 30226871.78 XPort_of_GazaPort_of_Latakia\n",
       " + 133474473.2 XPort_of_GazaPort_of_Mersin\n",
       " + 150185708.1 XPort_of_GazaPort_of_Salalah\n",
       " + 133005844.6 XPort_of_GazaPort_of_Shuwaikh\n",
       " + 216546853.3 XPort_of_GazaPort_of_Umm_Qasr <= 920430000\n",
       "\n",
       "_C76: 20211709.62 XPort_of_Jebel_AliLarnaca_Port\n",
       " + 52926740.45 XPort_of_Jebel_AliMina_Salman\n",
       " + 219933980 XPort_of_Jebel_AliPort_of_Alexandria\n",
       " + 107530347.6 XPort_of_Jebel_AliPort_of_Aqaba\n",
       " + 150919247.3 XPort_of_Jebel_AliPort_of_Bandar_Abbas\n",
       " + 49856593.12 XPort_of_Jebel_AliPort_of_Beirut\n",
       " + 55444187.63 XPort_of_Jebel_AliPort_of_Doha\n",
       " + 11357941.91 XPort_of_Jebel_AliPort_of_Gaza\n",
       " + 219082653.4 XPort_of_Jebel_AliPort_of_Haifa\n",
       " + 16109213.06 XPort_of_Jebel_AliPort_of_Hodeidah\n",
       " + 494016476.8 XPort_of_Jebel_AliPort_of_Jebel_Ali\n",
       " + 255172735.5 XPort_of_Jebel_AliPort_of_Jeddah\n",
       " + 255172735.5 XPort_of_Jebel_AliPort_of_King_Abdul_Aziz\n",
       " + 30226871.78 XPort_of_Jebel_AliPort_of_Latakia\n",
       " + 133474473.2 XPort_of_Jebel_AliPort_of_Mersin\n",
       " + 150185708.1 XPort_of_Jebel_AliPort_of_Salalah\n",
       " + 133005844.6 XPort_of_Jebel_AliPort_of_Shuwaikh\n",
       " + 216546853.3 XPort_of_Jebel_AliPort_of_Umm_Qasr <= 920430000\n",
       "\n",
       "VARIABLES\n",
       "0 <= XPort_of_GazaLarnaca_Port <= 1 Integer\n",
       "0 <= XPort_of_GazaMina_Salman <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Alexandria <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Aqaba <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Bandar_Abbas <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Beirut <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Doha <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Gaza <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Haifa <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Hodeidah <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Jebel_Ali <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Jeddah <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_King_Abdul_Aziz <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Latakia <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Mersin <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Salalah <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Shuwaikh <= 1 Integer\n",
       "0 <= XPort_of_GazaPort_of_Umm_Qasr <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliLarnaca_Port <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliMina_Salman <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Alexandria <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Aqaba <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Bandar_Abbas <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Beirut <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Doha <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Gaza <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Haifa <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Hodeidah <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Jebel_Ali <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Jeddah <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_King_Abdul_Aziz <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Latakia <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Mersin <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Salalah <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Shuwaikh <= 1 Integer\n",
       "0 <= XPort_of_Jebel_AliPort_of_Umm_Qasr <= 1 Integer\n",
       "0 <= XPort_of_SalalahLarnaca_Port <= 1 Integer\n",
       "0 <= XPort_of_SalalahMina_Salman <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Alexandria <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Aqaba <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Bandar_Abbas <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Beirut <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Doha <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Gaza <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Haifa <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Hodeidah <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Jebel_Ali <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Jeddah <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_King_Abdul_Aziz <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Latakia <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Mersin <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Salalah <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Shuwaikh <= 1 Integer\n",
       "0 <= XPort_of_SalalahPort_of_Umm_Qasr <= 1 Integer"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Setting up constraints\n",
    "plant_numbers=3\n",
    "prob+= sum(X[i][i] for i in supply_points)==plant_numbers\n",
    "\n",
    "for j in demand_points:\n",
    "    prob+= sum(X[i][j] for i in supply_points)==1\n",
    "    \n",
    "for j in demand_points:\n",
    "    for i in supply_points:\n",
    "        prob+= X[i][j]<=X[i][i] \n",
    "        \n",
    "for i in supply_points:\n",
    "    prob+= sum(vehicle_demands[j]*X[i][j] for j in demand_points) <= 920430000\n",
    "        \n",
    "prob\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Saving the model to a lp file\n",
    "prob.writeLP(\"p-median.lp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Status: Optimal\n",
      "Objective:  777329059977.0992\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'XPort_of_GazaLarnaca_Port': 1.0,\n",
       " 'XPort_of_GazaMina_Salman': 0.0,\n",
       " 'XPort_of_GazaPort_of_Alexandria': 1.0,\n",
       " 'XPort_of_GazaPort_of_Aqaba': 1.0,\n",
       " 'XPort_of_GazaPort_of_Bandar_Abbas': 0.0,\n",
       " 'XPort_of_GazaPort_of_Beirut': 1.0,\n",
       " 'XPort_of_GazaPort_of_Doha': 0.0,\n",
       " 'XPort_of_GazaPort_of_Gaza': 1.0,\n",
       " 'XPort_of_GazaPort_of_Haifa': 1.0,\n",
       " 'XPort_of_GazaPort_of_Hodeidah': 0.0,\n",
       " 'XPort_of_GazaPort_of_Jebel_Ali': 0.0,\n",
       " 'XPort_of_GazaPort_of_Jeddah': 0.0,\n",
       " 'XPort_of_GazaPort_of_King_Abdul_Aziz': 0.0,\n",
       " 'XPort_of_GazaPort_of_Latakia': 1.0,\n",
       " 'XPort_of_GazaPort_of_Mersin': 1.0,\n",
       " 'XPort_of_GazaPort_of_Salalah': 0.0,\n",
       " 'XPort_of_GazaPort_of_Shuwaikh': 0.0,\n",
       " 'XPort_of_GazaPort_of_Umm_Qasr': 0.0,\n",
       " 'XPort_of_Jebel_AliLarnaca_Port': 0.0,\n",
       " 'XPort_of_Jebel_AliMina_Salman': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Alexandria': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Aqaba': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Bandar_Abbas': 1.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Beirut': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Doha': 1.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Gaza': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Haifa': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Hodeidah': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Jebel_Ali': 1.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Jeddah': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_King_Abdul_Aziz': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Latakia': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Mersin': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Salalah': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Shuwaikh': 0.0,\n",
       " 'XPort_of_Jebel_AliPort_of_Umm_Qasr': 1.0,\n",
       " 'XPort_of_SalalahLarnaca_Port': 0.0,\n",
       " 'XPort_of_SalalahMina_Salman': 1.0,\n",
       " 'XPort_of_SalalahPort_of_Alexandria': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Aqaba': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Bandar_Abbas': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Beirut': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Doha': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Gaza': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Haifa': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Hodeidah': 1.0,\n",
       " 'XPort_of_SalalahPort_of_Jebel_Ali': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Jeddah': 1.0,\n",
       " 'XPort_of_SalalahPort_of_King_Abdul_Aziz': 1.0,\n",
       " 'XPort_of_SalalahPort_of_Latakia': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Mersin': 0.0,\n",
       " 'XPort_of_SalalahPort_of_Salalah': 1.0,\n",
       " 'XPort_of_SalalahPort_of_Shuwaikh': 1.0,\n",
       " 'XPort_of_SalalahPort_of_Umm_Qasr': 0.0}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Solving the model\n",
    "\n",
    "prob.solve()\n",
    "\n",
    "print(\"Status:\",LpStatus[prob.status]) \n",
    "print(\"Objective: \",value(prob.objective))\n",
    "varsdict = {}\n",
    "for v in prob.variables():\n",
    "    varsdict[v.name] = v.varValue\n",
    "varsdict "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
